package com.kuzufang.modules.search;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.kuzufang.R;
import com.kuzufang.base.BaseAdapter;
import com.kuzufang.utils.KZLog;
import com.kuzufang.view.SwitchView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by songyuanjin on 2017/9/25.
 */

public class RoommateConfigAdapter extends BaseAdapter<RoommateConfigAdapter.RoommateConfig, RoommateConfigAdapter.RoommateConfigHolder> {
    private List<RoommateConfig> configs = new ArrayList<>();

    public RoommateConfigAdapter(Context ctx) {
        super(ctx);

        configs.add(new RoommateConfig("女", "男"));
        configs.add(new RoommateConfig("早睡", "晚睡"));
        configs.add(new RoommateConfig("禁烟", "抽烟"));
        configs.add(new RoommateConfig("宠物", "禁养"));
        clear();
        addAll(configs);
        notifyDataSetChanged();
    }

    @Override
    protected void bindViewHolderData(RoommateConfigHolder viewHolder, RoommateConfig data, int position) {
        viewHolder.bindData(data, position);
    }

    @Override
    public RoommateConfigHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mCtx).inflate(R.layout.item_roommate_config_search, parent, false);
        return new RoommateConfigHolder(view);
    }

    class RoommateConfigHolder extends RecyclerView.ViewHolder {
        private SwitchView switchView;
        private LinearLayout itemContent;

        public RoommateConfigHolder(View itemView) {
            super(itemView);
            switchView = (SwitchView) itemView.findViewById(R.id.switch_roommate_config);
            itemContent = (LinearLayout) itemView.findViewById(R.id.item_root);
        }

        public void bindData(RoommateConfig config, int position) {
            switchView.setLeftShowTextView(config.getLeftString());
            switchView.setRightShowTextView(config.getRightString());
            if (position % 3 == 0) {
                itemContent.setGravity(Gravity.LEFT);
            } else if (position % 3 == 1) {
                itemContent.setGravity(Gravity.CENTER);
            } else {
                itemContent.setGravity(Gravity.RIGHT);
            }
            KZLog.d(config.toString());
        }
    }

    class RoommateConfig {
        private String leftString;
        private String rightString;

        public RoommateConfig(String leftString, String rightString) {
            this.leftString = leftString;
            this.rightString = rightString;
        }

        public String getLeftString() {
            return leftString;
        }

        public void setLeftString(String leftString) {
            this.leftString = leftString;
        }

        public String getRightString() {
            return rightString;
        }

        public void setRightString(String rightString) {
            this.rightString = rightString;
        }

        @Override
        public String toString() {
            return "RoommateConfig{" +
                    "leftString='" + leftString + '\'' +
                    ", rightString='" + rightString + '\'' +
                    '}';
        }
    }
}
